Skip to content

Add text output mode for auth token#4903

Open
simonfaltum wants to merge 1 commit intomainfrom
simonfaltum/auth-token-text-output
Open

Add text output mode for auth token#4903
simonfaltum wants to merge 1 commit intomainfrom
simonfaltum/auth-token-text-output

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

auth token always outputs JSON, ignoring the --output flag. If you want to pipe just the token string into another tool, you have to parse JSON. That's unnecessary friction for a common scripting pattern.

Changes

auth token now respects --output text when explicitly set, outputting just the access token string (with a trailing newline) suitable for piping. JSON remains the default for backward compatibility.

Only honors the explicit --output text flag, not implicit text mode (e.g. from DATABRICKS_OUTPUT_FORMAT), so existing scripts that parse JSON output won't break.

Also fixes discarded write errors (_, _ replaced with proper error returns).

Test plan

  • Unit tests for default (JSON), explicit --output json, and --output text modes
  • Existing cmd/auth tests pass

auth token now respects --output text when explicitly set, outputting
just the access token string suitable for piping. JSON remains the
default for backward compatibility.

Also returns write errors instead of discarding them.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Suggested reviewers

Based on git history of the changed files, these people are best suited to review:

Confidence: low

Eligible reviewers

Based on CODEOWNERS, these people or teams could also review:

@andrewnester, @anton-107, @denik, @shreyas-goenka

Suggestions based on git history of 2 changed files (2 scored). See CODEOWNERS for path-specific ownership rules.

Comment on lines +831 to +832
wantSubstr string
wantJSON bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we compare the whole output instead? This will require a single string no matter if the output is in text or JSON. Default JSON marshaling is deterministic so the output should be stable.

return cmd
}

func writeTokenOutput(cmd *cobra.Command, t *oauth2.Token) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing cmd couples this simple function to Cobra. Could we rather take a boolean isOutput or an enum as parameter? This would make the function trivial to test on its own without the need for any Cobra machinery.

return "<error>", nil
}

func TestTokenCommand_TextOutput(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels more complicated than it needs to be. Should we rather test the new private function you've added?

I'm fine with testing the whole command but then I think we should refactor it so that it allows easy injection of its dependencies (e.g. the token minting part).

Copy link
Copy Markdown
Contributor

@renaudhartert-db renaudhartert-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming resolution of the open comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants